Back to course home
0% completed
Vote For New Content
Amazon Hard Problems
Constrained Subsequence Sum (hard)
Solution: Constrained Subsequence Sum
Number of Valid Subarrays (hard)
Solution: Number of Valid Subarrays
Count Vowels Permutation (hard)
Solution: Count Vowels Permutation
Concatenated Words (hard)
Solution: Concatenated Words
Minimum Replacements to Sort the Array (hard)
Solution: Minimum Replacements to Sort the Array
Count All Valid Pickup and Delivery Options (hard)
Solution: Count All Valid Pickup and Delivery Options
Length of the Longest Valid Substring (hard)
Solution: Length of the Longest Valid Substring
Count Array Pairs Divisible by K (hard)
Solution: Count Array Pairs Divisible by K
Word Ladder (hard)
Solution: Word Ladder
Path with Maximum Sum (hard)
Solution: Path with Maximum Sum
Deepest Leaves Sum (medium)
Problem Statement
Given a root node of the binary tree, return the sum of all values located at the deepest leaves of a binary tree.
Examples
- Example 1:
- Input: root =
[1,2,3,4,5,null,7]
- Input: root =
-
Expected Output:
16 -
Justification: The deepest level contains the nodes with values 4, 5, and 7, and their sum is 16.
-
Example 2:
- Input: root =
[6,2,8,null,null,7,9,null,null,null,10]
- Input: root =
-
Expected Output:
10 -
Justification: The deepest level contains only one node with the value 10, thus the sum is 10.
-
Example 3:
- Input: root =
[1,null,2,null,3,null,4]
- Input: root =
- Expected Output:
4 - Justification: The binary tree's deepest level has a single node with the value 4. Since it's the only node at that level, the sum is 4.
Try it yourself
Try solving this question here:
Java
Saved to Cloud
. . . .
Solution: Maximum Difference Between Node and Ancestor
Solution: Deepest Leaves Sum
Mark as Completed
On this page
Problem Statement
Examples
Try it yourself